package com.seahorse.youliao.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.seahorse.youliao.service.SysRoleService;
import com.seahorse.youliao.service.entity.SysRoleDTO;
import com.seahorse.youliao.utils.BeanUtil;
import com.seahorse.youliao.vo.request.SysRoleQueryVO;
import com.seahorse.youliao.vo.response.SysRolePageInfoVO;
import com.seahorse.youliao.vo.response.SysRoleResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* describe: 角色信息表
* @author : songqiang
* @date: 2020-01-17 09:23:45.558
**/
@RestController
@Api("SysRoleController")
@RequestMapping("sysRole")
@Validated
public class SysRoleController {
	
    private static final Logger LOGGER = LoggerFactory.getLogger(SysRoleController.class);
    
	@Autowired
    private SysRoleService sysRoleService;
    /**
     * 分页查询
     * @param sysRoleQueryVO 分页查询参数
     * @return 分页参数
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("getPageList")
    public SysRolePageInfoVO selectPageList(@RequestBody @Valid SysRoleQueryVO sysRoleQueryVO) {
        String info = String.format("The method name[selectPageList] params:%s", sysRoleQueryVO.toString());
        LOGGER.info(info);
        SysRoleDTO sysRole = BeanUtil.convert(sysRoleQueryVO, SysRoleDTO.class);

        Page<SysRoleResponseVO> page = PageHelper.startPage(sysRoleQueryVO.getPageNum(), sysRoleQueryVO.getPageSize());
        List<SysRoleDTO> sysRoleList = sysRoleService.getList(sysRole);
        SysRolePageInfoVO sysRolePageInfo = new SysRolePageInfoVO();
        BeanUtils.copyProperties(page.toPageInfo(), sysRolePageInfo);
        List<SysRoleResponseVO> voList = BeanUtil.convert(sysRoleList, SysRoleResponseVO.class);
        sysRolePageInfo.setList(voList);

        return sysRolePageInfo;
    }


}
